package com.xinrui.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xinrui.sunnyday.constant.MessageConstant;
import com.xinrui.sunnyday.entity.QueryPageBean;
import com.xinrui.sunnyday.entity.Result;
import com.xinrui.sunnyday.pojo.Setmeal;
import com.xinrui.sunnyday.service.SetMealMobileService;
import com.xinrui.sunnyday.service.SetMealService;
import com.xinrui.sunnyday.utils.QiNiuUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/setMealMobile")
public class SetMealMobileController {

    @Reference
    private SetMealMobileService setMealMobileService;

    /**
     * 查询套餐不分页
     *
     * @return
     */
    @GetMapping("/findAllMealMobile")
    public Result findAllMealMobile() {
        List<Setmeal> list = setMealMobileService.findAllMealMobile();
//        拼接
        list.forEach(ing -> {
            ing.setImg(QiNiuUtils.DOMAIN + ing.getImg());
        });

        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, list);
    }

    /**
     * 多表联查：套餐详细信息
     * @param id
     * @return
     */
    @GetMapping("/findDetailById")
    public Result findDetailById(Integer id) {
        Setmeal setmeal = setMealMobileService.findDetailById(id);
//        拼接
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }
}
